<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class UploadFile
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $actionAll = ['config','uploadimage','uploadscrawl','uploadvideo','uploadfile','listimage','listfile','catchimage'];
        $actionWhite = ['config','uploadimage'];
        $actionBlack = ['uploadscrawl','uploadvideo','uploadfile','listimage','listfile','catchimage'];
        $action = $request->get('action');
       if(empty(auth()->user())){
           return redirect()->route('admin.index');
       } 
        if(!access()->allow('vuls-add')){
            abort('500','无访问权限');
        }
        if(in_array($action,$actionBlack)){
            abort('500','无访问权限');
        }
        return $next($request);
    }
}
